/*******************************************************
> Copyright (C) 2024 ==IOT== All rights reserved.
> File Name: inherit3.cpp
> Author: IOT
> Website:www.slq.org
> Created Time: 2024年10月24日 星期四 15时50分39秒
***************************************************/

#include <iostream>
using namespace std;

class Base {
	
	int m = 32;
	
	public:
		virtual void show() // 由关键字virtual修饰的函数，叫虚函数
		{
			cout << "基类的show" << endl;
		}
};

class Derived : public Base {
	public:
		virtual void show () // 同名同参，不同函数体，构成重写(overwite)
		{
			cout << "派生类的show" << endl;
		}
};

void func(Base *base) // 相同的func,不同类型的对象
{
	base->show(); // 调用不同的对象函数，得到不同的结果
}

int main(int argc,const char* argv[])
{
	Base base;
	base.show();
	
	int *pm = (int *)&base;
	
	cout << "*pm = " << *(int *)((char *)pm + 8) << endl;
	
	Derived der;
	der.show(10);
	
	cout << "size of base:" << sizeof(base) << ", address:" << &base << endl;
	cout << "size of der:" << sizeof(der) << ", address:" << &der << endl;
	
	//base = 10;
	Base *p = &der; // 赋值兼容
	p->show(); // (*p).show();
	
	Base &rbase = der;
	rbase.show();
	
	p = &base;
	p->show();
	
	
	func(base);
	func(der);
	
    return 0;
}
